package com.daocao.hua.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.daocao.hua.R;
import com.daocao.hua.constant.Const;
import com.daocao.hua.event.OnEndIdentityMsg;
import com.daocao.hua.util.DisplayUtil;
import com.daocao.hua.util.StatusBarCompat;
import com.daocao.hua.util.Util;
import com.daocao.hua.view.CircularProgress;
import com.daocao.hua.view.Dialog;
import com.readystatesoftware.systembartint.SystemBarTintManager;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 2017/7/25.
 */

public class ChsiQuestionActivity extends BaseActivity {
    @BindView(R.id.txt_one)
    TextView txtOne;
    @BindView(R.id.txt_two)
    TextView txtTwo;
    @BindView(R.id.progressBar)
    CircularProgress progressBar;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    //    @BindView(R.id.btn_back)
//    ImageView btnBack;
    private Unbinder unbiner;
    private boolean ifFirstload = true;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.chsi_question_v2_activity);
        baseInitView(this, "ChsiQuestionActivity", Const.ViewType.ACTIVITY);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintColor(Color.TRANSPARENT);
            tintManager.setNavigationBarTintColor(Color.parseColor("#000000"));
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setNavigationBarTintEnabled(true);
        }
        unbiner = ButterKnife.bind(this);
        init();
    }

    private void init() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            txtTitle.post(new Runnable() {
                @Override
                public void run() {
                    int height = StatusBarCompat.getStatusBarHeight(ChsiQuestionActivity.this);
                    if (height == 0) {
                        return;
                    }
                    int left = DisplayUtil.dip2px(ChsiQuestionActivity.this, 10);
                    txtTitle.setPadding(2 * left, height + 2 * left, 0, left);
                }
            });
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbiner.unbind();
    }

    @OnClick({R.id.txt_question_one, R.id.txt_question_two, R.id.layout_register, R.id.layout_forget, R.id.btn_finish})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.txt_question_one:
                Intent intent = new Intent(this, HelpDetailActivity.class);
                intent.putExtra("id", "943");
                intent.putExtra("type", Const.FragmentType.HELP);
                startActivity(intent);
                overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                break;
            case R.id.txt_question_two:
                Intent intentTwo = new Intent(this, HelpDetailActivity.class);
                intentTwo.putExtra("id", "944");
                intentTwo.putExtra("type", Const.FragmentType.HELP);
                startActivity(intentTwo);
                overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                break;
            case R.id.layout_register:
                Util.startActivity(this, ChsiRegisterV2Activity.class);
                break;
            case R.id.layout_forget:
                Util.startActivity(this, ChsiForgetPwdV2Activity.class);
                break;
            case R.id.btn_finish:
                showDialog();
                break;
        }
    }

    private void showDialog() {
        String content = "要放弃借款吗？";

        Dialog.showDefaultRedBlackDialog(this, "提示", content, "放弃", "继续", true, new Dialog.DialogDefaultClickListener() {
            @Override
            public void confirm() {

            }

            @Override
            public void cancel() {
                EventBus.getDefault().post(new OnEndIdentityMsg());
                finish();
            }
        });
    }
}
